package controller.admin;

import Message.DTO.CategoryDTO;
import Message.PageResult;
import Message.Result;
import Message.vo.CategoryPageVO;
import Message.vo.CategoryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import service.CategoryRelatedService;

import java.util.List;

@Slf4j
@RequestMapping("/admin/category")
@RestController
public class CategoryController {
    @Autowired
    private CategoryRelatedService categoryRelated;
    @GetMapping("/page")
    public Result SelectPage(CategoryPageVO categoryPage){
          log.info("输入数据",categoryPage);
        PageResult pageResult = categoryRelated.SelectPage(categoryPage);
       return Result.success(pageResult);
    }

    @PutMapping("")
    public Result UpdateCategory(@RequestBody CategoryVO category){
        categoryRelated.UpdateCategory(category);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result UpdateCategoryStatus(@PathVariable Integer status,long id){
        categoryRelated.UpdateCategoryStatus(status,id);
    return Result.success();
    }
    @DeleteMapping("")
    public Result DeleteCategory(Long id){
        categoryRelated.DeleteCategory(id);

    return Result.success();
    }
    @PostMapping("")
    public Result AddCategory(@RequestBody CategoryDTO category) throws Exception {

        categoryRelated.AddCategory(category);
        return Result.success();


    }    @GetMapping("/list")
    public Result ListCategory(@RequestParam("type") Integer type){

        List category = categoryRelated.ListCategory(type);

        return Result.success(category);
    }
    }













